# jose espina

# cmake version needed
cmake_minimum_required(VERSION 2.6)

#set(PFUNIT_LIBDIR $(PFUNIT)/source)
#set(PFUNIT_INCDIR ?=$(PFUNIT)/include)
#set(PFUNIT_MODDIR ?=$(PFUNIT)/source)
#set(PFUNIT_BINDIR ?=$(PFUNIT)/bin)

#set(F90FLAGS +=-I$(PFUNIT_MODDIR))
#set(LDFLAGS  +=-L$(PFUNIT_LIBDIR) -lpfunit)



# name of the project
project(winpos)

# fortran language is set
enable_language(Fortran)


#link_directories(${CMAKE_BINARY_DIR}/lib})

#ADD_DEFINITIONS("-L/home/jose/Apps/fortran/pfunit/source -lpfunit")

# libraries are added
#add_library(vector SHARED VectorOperations.F90)
#add_library(tests SHARED tests.F90)
#add_library(driver SHARED driver.F90)
#add_executable(runTests driver.F90)

#target_link_libraries(tests vector)
#target_link_libraries(driver tests)

#target_link_libraries(runTests tests)

add_custom_command(
        OUTPUT VectorOperations.o
        COMMAND gfortran -c -I/opt/repos/pf/mod VectorOperations.F90
        COMMENT "compiling vector operations"
)
add_custom_target(vector ALL DEPENDS VectorOperations.o)


add_custom_command(
        OUTPUT tests.o
        COMMAND gfortran -c -I/opt/repos/pf/mod tests.F90
        COMMENT "compiling tests"
)
add_custom_target(tests ALL DEPENDS tests.o)


add_custom_command(
        OUTPUT driver.o
        COMMAND gfortran -c -I/opt/repos/pf/mod driver.F90
        COMMENT "compiling driver"
)
add_custom_target(driver ALL DEPENDS driver.o)

add_custom_command(
	OUTPUT simple.x
	COMMAND gfortran -o simple.x tests.o driver.o VectorOperations.o -L/opt/repos/pf/lib -lpfunit
	COMMENT "creating exe"
)
add_custom_target(correctm ALL DEPENDS simple.x) 

add_dependencies(correctm vector)
add_dependencies(correctm tests)
add_dependencies(correctm driver)

#install (TARGETS runTests DESTINATION bin)

include(CTest)
enable_testing()
add_test(test1 simple.x hola)

#add_test(nombre executable params)


#to add custom targets in generated makefile add the following:
#add_custom_target(

#add_custom_target(unittest
#	OUTPUT driver.F90
#	COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/driver.F90
#	DEPENDS MakeTable
#	)

#add_custom_command(
#	OUTPUT output
#	COMMAND g95 
